package cn.xjt.demo03;

/**
 * @author xujiangtao
 * @create 2020-08-01-10:16
 */
public class TestState {
    public static void main(String[] args) throws InterruptedException {
        //通过lamda表他是创建了一个线程
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("线程循环了");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("//////////////");
        });
        //测试线程未启动状态
        Thread.State s = thread.getState();
        System.out.println(s);          //new
        //测试线程启动后
        thread.start();
        s=thread.getState();
        System.out.println(s);          //RUNANBLE
        //测试线程等待的状态
        while(s!=Thread.State.TERMINATED)       //只要状态不是终止状态，就一直循环
        {
            Thread.sleep(100);          //让线程等待0.1秒
            s=thread.getState();                   //得到线程的状态
            System.out.println(s);                 //输出状态
        }
    }
}
